﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class InventorySlot : MonoBehaviour 
{	
	public Item item;
	public int number;
	[HideInInspector]public Transform player;
	private Drop dropOption;
	public Image image;
	public Sprite emptySprite;

	void Awake()
	{	
		dropOption = GetComponent<Drop>();
		if (item == null)
		{
			dropOption.enabled = false;
		}
	}



	public void Add(Item itemToAdd)
	{	
		this.item = itemToAdd;
		image.sprite = item.icon;
		dropOption.enabled = true;
		dropOption.actionName = "Drop " + item.name;
	}

	public void Clear()
	{
		item = null;
		image.sprite = emptySprite;
		dropOption.enabled = false;
	}
	public void Drop()
	{	
		if (item!=null)
		{
			PhotonNetwork.Instantiate(item.prefab.name,GameFunctions.PlanarPosition(player.position,0),player.rotation,0);
		}
		
		Clear();
	}
}
